import request from '@/utils/request'
import { SET_TOKEN } from '@/store/actionType'
import { setToken } from '@/utils/storage'
export function login (data) {
  return async dispatch => {
    // 发请求 做登录.....
    const res = await request.post('/authorizations', data)
    console.log(2)
    console.log('login', data, res)
    //  获取到的token是 res.data.token

    // 保存到redux
    dispatch({
      type: SET_TOKEN,
      payload: res.data.token
    })

    // 持久化
    setToken(res.data.token)
  }
}
